package dna;

import core.inputoutput.converters.FormatConverter;
import core.inputoutput.formatting.Format;
import core.molecules.atoms.Atom;
import core.molecules.organic.OrganicCompound;
import dna.macromolecules.DNAStrand;
import dna.macromolecules.DNAStructure;
import dna.nucleosides.Nucleoside;

public class DNAshifter extends FormatConverter<DNAStructure> {

	public DNAshifter(Format f) {
		super(f);
	}

	@Override
	public String applyConverter(DNAStructure data) {
		
		return this.applyConverter(data, 0, 0, 0);
	}
	
	public String applyConverter(DNAStructure data, double dx, double dy, double dz) {
		return this.applyConverter(data, dx,dy, dz, 0);
	}

	/**
	 * Shifts the input DNAStructure by the input dValues and adjusts the StrandID by a factor of n if input
	 * @param data
	 * @param dx
	 * @param dy
	 * @param dz
	 * @param n
	 * @return
	 */
	public String applyConverter(DNAStructure data, double dx, double dy, double dz, int n) {
		StringBuilder sb = new StringBuilder();
		for(DNAStrand strand : data){
			notifyObservers("Strand " + data.indexOf(strand) + "of " + data.size()); //print update of status
			for (Nucleoside nuc: strand){
				for(OrganicCompound oc: nuc.getSubMolecules()){
					for (Atom a: oc){
						sb.append(this.createEntry(myFormat, 
								"ATOM",
								a.getID().toString(),
								a.getAtomCode(),
								nuc.getAbbr(),
								"",
								nuc.getID().toString(),
								trimDoubleToSize(Double.toString(a.getPosition().getX()+dx)),
								trimDoubleToSize(Double.toString(a.getPosition().getY()+dy)),
								trimDoubleToSize(Double.toString(a.getPosition().getZ()+dz)),
								"1.00",
								"0.00",
								((Integer)(strand.getID()+data.last().getID()*n)).toString(),
								a.getAbbr()));
					}
				}
			}
		}
		
		return sb.toString();
	}


}
